home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 201-225 / disk_222 / plplot / src / source.zoo / plxybx.c < prev    next >
C/C++ Source or Header  |  1989-05-15  |  4KB  |  138 lines

  1. /* This draws a sloping line from (wx1,wy1) to (wx2,wy2)             */
  2. /*  which represents an axis of a 3-d graph with data values from    */
  3. /*  "vmin" to "vmax". Depending on "opt", vertical ticks and/or      */
  4. /*  subticks are placed on the line at major tick interval "tick"    */
  5. /*  with "nsub" subticks between major ticks. If "tick" and/or       */
  6. /*  "nsub" is zero, automatic tick positions are computed            */
  7.  
  8. /* B: Draw box boundary                                              */
  9. /* I: Inverts tick marks (i.e. drawn downwards)                      */
  10. /* L: Logarithmic axes, major ticks at decades, minor ticks at units */
  11. /* N: Write numeric label                                            */
  12. /* T: Draw major tick marks                                          */
  13. /* S: Draw minor tick marks                                          */
  14. /* U: Write label on line                                            */
  15.  
  16. #include "plplot.h"
  17. #include <stdio.h>
  18. #include <math.h>
  19.  
  20. #define  betw(c,a,b)  ((a <= c && c <= b) || (b <= c && c <= a))
  21.  
  22. static float xlog[8] = 
  23.   {0.301030,0.477121,0.602060,0.698970,0.778151,0.845098,0.903090,0.954243};
  24.  
  25. void plxybx(opt,label,wx1,wy1,wx2,wy2,vmin,vmax,tick,nsub,nolast)
  26. char *opt, *label;
  27. float wx1, wy1, wx2, wy2, vmin, vmax, tick;
  28. int nsub, nolast;
  29. {
  30.       char string[40];
  31.       int lb,li,ll,ln,ls,lt,lu;
  32.       int major, minor, mode, prec;
  33.       int i, i1, i2, i3, i4;
  34.       int nsub1;
  35.       float xpmm, ypmm, defmaj, defmin, htmaj, htmin, tick1;
  36.       float pos, tn, tp, temp;
  37.       float dwx, dwy, lambda;
  38.  
  39.       dwx = wx2 - wx1;
  40.       dwy = wy2 - wy1;
  41.  
  42. /* Tick and subtick sizes in device coords */
  43.  
  44.       gpixmm(&xpmm,&ypmm);
  45.       gmaj(&defmaj,&htmaj);
  46.       gmin(&defmin,&htmin);
  47.       
  48.       major=max(round(htmaj*ypmm),1);
  49.       minor=max(round(htmin*ypmm),1);
  50.  
  51.       tick1=tick;
  52.       nsub1=nsub;
  53.  
  54.       lb=strpos(opt,'B')!=-1||strpos(opt,'b')!=-1;
  55.       li=strpos(opt,'I')!=-1||strpos(opt,'i')!=-1;
  56.       ll=strpos(opt,'L')!=-1||strpos(opt,'l')!=-1;
  57.       ln=strpos(opt,'N')!=-1||strpos(opt,'n')!=-1;
  58.       ls=strpos(opt,'S')!=-1||strpos(opt,'s')!=-1;
  59.       lt=strpos(opt,'T')!=-1||strpos(opt,'t')!=-1;
  60.       lu=strpos(opt,'U')!=-1||strpos(opt,'u')!=-1;
  61.  
  62.       if (lu) plxytx(wx1,wy1,wx2,wy2,3.2,0.5,0.5,label);
  63.       if (!lb) return;
  64.    
  65.       if (ll) tick1 = 1.0;
  66.       if (lt) pldtik(vmin,vmax,&tick1,&nsub1,&mode,&prec);
  67.  
  68.       if (li) {
  69.         i1 = minor;
  70.         i2 = 0;
  71.         i3 = major;
  72.         i4 = 0;
  73.       }
  74.       else  {
  75.         i1 = 0;
  76.         i2 = minor;
  77.         i3 = 0;
  78.         i4 = major;
  79.       }  
  80.  
  81. /* Draw the line */
  82.  
  83.       movwor(wx1,wy1);
  84.       if (lt) {
  85.         tp=tick1*floor(vmin/tick1);
  86. lab2:
  87.         tn=tp+tick1;
  88.         if (ls) {
  89.           if (ll) {
  90.             for (i=0; i<=7; i++)  {
  91.               temp=tp+xlog[i];
  92.               if (betw(temp,vmin,vmax)) {
  93.                 lambda = (temp-vmin)/(vmax-vmin);
  94.                 plxtik(wcpcx(wx1+lambda*dwx),wcpcy(wy1+lambda*dwy),i1,i2);
  95.               }
  96.             }
  97.           }
  98.           else  {
  99.             for(i=1; i <= nsub1-1; i++)  {
  100.               temp=tp+i*(tn-tp)/nsub1;
  101.               if (betw(temp,vmin,vmax)) {
  102.                 lambda = (temp-vmin)/(vmax-vmin);
  103.                 plxtik(wcpcx(wx1+lambda*dwx),wcpcy(wy1+lambda*dwy),i1,i2);
  104.               }
  105.             }
  106.           }
  107.         }
  108.         temp=tn;
  109.         if (betw(temp,vmin,vmax)) {
  110.           lambda = (temp-vmin)/(vmax-vmin);
  111.           plxtik(wcpcx(wx1+lambda*dwx),wcpcy(wy1+lambda*dwy),i3,i4);
  112.           tp=tn;
  113.           goto lab2;
  114.         }
  115.       }
  116.  
  117.       drawor(wx2,wy2);
  118.  
  119. /* Label the line */
  120.  
  121.       if (ln && lt) {
  122.         tp=tick1*floor(vmin/tick1);
  123. lab82:
  124.         tn=tp+tick1;
  125.         if (nolast && !betw(tn+tick1,vmin,vmax)) return;
  126.         if (betw(tn,vmin,vmax)) {
  127.           if (!ll) 
  128.             plform(tn,mode,prec,string);
  129.           else 
  130.             sprintf(string,"10\\u%-d",round(tn));
  131.           pos=(tn-vmin)/(vmax-vmin);
  132.           if (ln) plxytx(wx1,wy1,wx2,wy2,1.5,pos,0.5,string);
  133.           tp=tn;
  134.           goto lab82;
  135.         }
  136.       }
  137. }
  138.